package com.shyfu.entities;

import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.sql.Timestamp;

/**
 * Created by Svitlana on 03-Apr-14.
 */
@Entity
@Table(name = "COMMENTS", schema = "SHYFU", catalog = "")
public class Comment {
    private long commId;
    @NotNull
    @NotEmpty
    @Size(max = 1000)
    private String content;
    @NotNull
    private Timestamp created;
    private User user;
    private Book book;

    @Id
    @Column(name = "COMM_ID", nullable = false, insertable = true, updatable = true, precision = 0)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "comment_seq")
    @SequenceGenerator(name = "comment_seq", sequenceName = "COMMENTIDSEQUENCE", allocationSize = 1)
    public long getCommId() {
        return commId;
    }

    public void setCommId(long commId) {
        this.commId = commId;
    }

    @Basic
    @Column(name = "CONTENT", nullable = false, insertable = true, updatable = true, length = 1000)
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Basic
    @Column(name = "CREATED", nullable = false, insertable = true, updatable = true)
    public Timestamp getCreated() {
        return created;
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }

    @ManyToOne
    @JoinColumn(name = "USER_ID")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne
    @JoinColumn(name = "BOOK_ID")
    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Comment comment = (Comment) o;

        if (commId != comment.commId) return false;
        if (content != null ? !content.equals(comment.content) : comment.content != null) return false;
        if (created != null ? !created.equals(comment.created) : comment.created != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        long result = commId;
        result = 31 * result + (content != null ? content.hashCode() : 0);
        result = 31 * result + (created != null ? created.hashCode() : 0);
        return ((Long) result).intValue();
    }
}
